﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Manager.aspx.cs" Inherits="Admin_Manager" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Page config file manager</title>
    </head>
    <body>
        <form id="form1" runat="server">

            <div style="width: 230px; float: left; border: solid 1px red; margin-right: 5px; padding: 5px;">
                <asp:Button Text="Creat New" ID="btnNew" runat="server" OnClick="btnNew_Click" />
                <br />
            
                <asp:PlaceHolder ID="phCreatNew" Visible="false" runat="server">
                    <div style="font: normal 10px tahoma; padding: 10px 0;">
                        Lưu ý: file name (.config) phải tồn tại trong thư mục Admin/Config/
                    </div>
                    File Name: <asp:TextBox ID="NameNew" Runat="server"></asp:TextBox>
                    <br />
                    <asp:Label ID="lbErrorConfig" runat="server"/>
                    <br /><br />
                
                    <asp:Button runat="server" ID="btnSubmit" Text="Submit" OnClick="btnSubmit_Click"/>
                    <asp:Button runat="server" ID="btnCancel" Text="Cancel" OnClick="btnCancel_Click"/>
                </asp:PlaceHolder>
            </div>
        
            <div style="width: 350px; float: left;">
                <asp:SqlDataSource ID="sqlDataConfig" runat="server" 
                                   ConnectionString="<%$ appSettings:connection-string %>"
                                   DeleteCommand="DELETE [Page] WHERE [Page_Id] = @Page_Id" 
                                   SelectCommand="SELECT * FROM [Page]  Order by [Name]" 
                                   UpdateCommand="UPDATE [Page] SET [Name]=@Name, [Content]=@Content WHERE [Page_Id] = @Page_Id" >
                    <DeleteParameters>
                        <asp:Parameter Name="Page_Id" Type="Int32" />
                    </DeleteParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="Name" Type="String" />
                        <asp:Parameter Name="Content" Type="String" />
                        <asp:Parameter Name="Page_Id" Type="Int32" />
                    </UpdateParameters>
                </asp:SqlDataSource>
             
                <asp:GridView ID="GridView1" DataKeyNames="Page_Id" DataSourceID="sqlDataConfig" runat="server" AutoGenerateColumns="false">
                    <Columns>
                    
                        <asp:BoundField HeaderText="Page Id" DataField="Page_Id" SortExpression="Page_Id" ReadOnly="true">
                        </asp:BoundField>

                        <asp:TemplateField HeaderText="Name">
                            <EditItemTemplate>
                                <asp:TextBox ID="NameEdit" Runat="server"
                                             Text='<%#Bind("Name")%>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label Runat="server"
                                           Text='<%#Bind("Name")%>' 
                                           ID="NameShow"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Content">
                            <EditItemTemplate>
                                <asp:TextBox ID="ContentEdit" Runat="server"  TextMode="multiLine" Rows="10" Columns="50"
                                             Text='<%#Bind("Content")%>'></asp:TextBox>
                            </EditItemTemplate>
                        </asp:TemplateField>
                        <asp:CommandField ShowEditButton="True" ShowDeleteButton="true"></asp:CommandField>
                    </Columns>
                </asp:GridView>
                <br class="clear"/>
            </div>
        </form>
    </body>
</html>